<template>
  <div class="login-container">
    <el-form :model="ruleForm2" :rules="rules2"
             status-icon
             ref="ruleForm2"
             label-position="left"
             label-width="0px"
             class="demo-ruleForm login-page">
      <h3 class="title">系统登录</h3>
      <el-form-item prop="username">
        <el-input type="text"
                  v-model="ruleForm2.username"
                  auto-complete="off"
                  placeholder="用户名"
        ></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password"
                  v-model="ruleForm2.password"
                  auto-complete="off"
                  placeholder="密码"
        ></el-input>
      </el-form-item>
      <el-form-item  prop="code">
        <el-input
          v-model="ruleForm2.code"
          placeholder="验证码"
          prefix-icon="lj-icon-yanzhengma"
          autocomplete="off"
          autocapitalize="off"
          spellcheck="false"
          maxlength="4"
          style="float: left; width: 122px; line-height: 60px"
        ></el-input>
        <div class="captcha_code">
          <img :src="imageBase64" @click="handleCaptchaImage">
        </div>
      </el-form-item>
      <el-checkbox
        v-model="checked"
        class="rememberme"
      >记住密码
      </el-checkbox>
      <el-form-item style="width:100%;">
        <el-button type="primary" style="width:100%;" @click="login" >登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {getCaptchaImage,userLogin} from "@/api/login/login";


export default {
  data() {
    return {

      ruleForm2: {
        username: 'admin',
        password: 'rgs666',
        code: null,
        uuid: null
      },
      rules2: {
        username: [{required: true, message: 'please enter your account', trigger: 'blur'}],
        password: [{required: true, message: 'enter your password', trigger: 'blur'}],
        code: [{required: true, message: 'enter your code', trigger: 'blur'}]
      },
      checked: false,
      uuid: null,
      imageBase64: null,
      token: null
    }
  },
  created() {
    this.handleCaptchaImage()
  },
  methods: {
    /** 获取验证码 */
    handleCaptchaImage() {
      getCaptchaImage().then(response => {
        this.uuid = response.data.data.uuid;
        this.imageBase64 = 'data:image/png;base64,'+response.data.data.imageBase64;
      });
    },
    /* 登录接口  */
    login(){
      //this.loading = true
      this.ruleForm2.uuid = this.uuid;
      userLogin(this.ruleForm2).then(response => {
        alert("hello")
        this.$store.commit("set_token", response.data.data);
        this.$router.push("/HelloWorld");
      })
    }
  }
}
</script>

<style scoped>
.login-container {
  width: 100%;
  height: 100%;
}

.login-page {
  -webkit-border-radius: 5px;
  border-radius: 5px;
  margin: 180px auto;
  width: 350px;
  padding: 35px 35px 15px;
  background: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
}

label.el-checkbox.rememberme {
  margin: 0px 0px 15px;
  text-align: left;
}
</style>

